package kama;

import java.util.Arrays;
import java.util.Scanner;

public class Test0056 {
}

class Main0056_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] split = scanner.nextLine().split(" ");
        int limit = Integer.parseInt(split[0]);
        int kind = Integer.parseInt(split[1]);

        int[][] info = new int[kind][3];
        for (int i = 0; i < 3; i++) {
            split = scanner.nextLine().split(" ");
            for (int j = 0; j < kind; j++) {
                info[j][i] = Integer.parseInt(split[j]);
            }
        }

        int[] dp = new int[limit + 1];
        Arrays.fill(dp,-1);
        dp[0] = 0;

        int ans = 0;
        for (int[] now : info) {
            int weight = now[0];
            int value = now[1];
            int count = now[2];

            while (count-- > 0){
                for (int i = limit; i >= weight; i--) {
                    if (dp[i-weight] == -1) continue;
                    dp[i] = Math.max(dp[i], dp[i-weight] + value);
                    ans = Math.max(ans, dp[i]);
                }
            }
        }

        System.out.println(ans);
    }
}
